const db = wx.cloud.database().collection("users")
const app = getApp()
var _id=0
Page({
  data: {
    remainanswer:0
  },
  onLoad: function() {
    var that=this
    db.where({
      _openid:app.globalData.openid
    }).get({
      success(res){
        _id=res.data[0]._id
        app.globalData.frequency=res.data[0].frequency
        that.setData({
          remainanswer:res.data[0].frequency
        })
      },
    })
  },
   //窗口跳转
   jumppage:function(){
     var that=this
    app.globalData.frequency-=1
    that.getdata()
    this.setData({
      remainanswer:app.globalData.frequency
    })
    wx.navigateTo({
      url: '/pages/answering/answering',
    })
  },
    //查询数据+改数据
    getdata:function(){
      db.where({
        _openid:app.globalData.openid
      }).get({
        success(res){
          _id=res.data[0]._id
          db.doc(_id).update({
            data:{
              frequency:app.globalData.frequency
            },
          })
        },
      })
    },
})